package com.rx.base.demo.common;

import lombok.Data;

@Data
public class BaseResult<T> {
    String code = "0";
    String msg;
    T data;

    public static<T> BaseResult<T> success(T data) {
        BaseResult<T> baseResult = new BaseResult<>();
        baseResult.data = data;
        return baseResult;

    }

    public static BaseResult<String> success() {
        return new BaseResult<String>();

    }

    public static BaseResult<String> error(RuntimeException e) {
        BaseResult<String> baseResult = new BaseResult<>();
        baseResult.setCode("500");
        baseResult.setMsg(e.getMessage());
        return baseResult;
    }

    public static BaseResult<String> error(String code, String msg) {
        BaseResult<String> baseResult = new BaseResult<>();
        baseResult.setCode(code);
        baseResult.setMsg(msg);
        return baseResult;
    }
}
